/*
 * @Author: frankiez 
 * @Description: 屏幕适配模块
 * @Date: 2017-01-13 04:08:18 
 * @Last Modified by: frankiez
 * @Last Modified time: 2017-01-13 04:08:38
 */


define(function() {
    // 自适应宽度
    var fitWindow = function() {
        var docEl = document.documentElement,
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
            recalc = function () {
                var clientWidth = docEl.clientWidth;
                if (!clientWidth) return;
                docEl.style.fontSize = 100 * (clientWidth / 375) + 'px';
            };
    
        // Abort if browser does not support addEventListener
        if (!document.addEventListener) return;
        window.addEventListener(resizeEvt, recalc, false);
        document.addEventListener('DOMContentLoaded', recalc, false);
        recalc();
    };

    // 屏幕ratio获取
    var setScreenRatio = function() {
        var ratio = 1;
        if (window.devicePixelRatio > 1) ratio = 2;
        document.body.className = 'ratio-' + ratio + 'x';
    };

    return {
        fitWindow: fitWindow,
        setScreenRatio: setScreenRatio
    };
});